function add_field(name) {
  var divs = YAHOO.util.Dom.getElementsByClassName("row-"+name);
  // Use the first one to clone.
  var row = divs[0]
  var lastRow = divs[divs.length-1];

  // Enable the delete button before the clone, we want all rows to have one
  // when there is more than one row.
  var inputs = YAHOO.util.Dom.getElementsByClassName("hcp-button-delete", null, row);
  YAHOO.util.Dom.setStyle(inputs[0], "display", "inline");

  // deep=true
  var newRow = row.cloneNode(true);
  var inputNode = getChildByName(newRow, name);

  // id is only used for the label, just get rid of it instead of dealing with
  // renumbering.
  inputNode.removeAttribute("id");

  // Remove any errors.
  // XXX

  // Clear the input.
  inputNode.value = "";

  // Set the display of the add buttons on new row.
  var inputs = YAHOO.util.Dom.getElementsByClassName("hcp-button-add", null, newRow);
  YAHOO.util.Dom.setStyle(inputs[0], "display", "inline");

  // Set the display of the add buttons on other rows.
  var inputs = YAHOO.util.Dom.getElementsByClassName("hcp-button-add", null, lastRow);
  YAHOO.util.Dom.setStyle(inputs[0], "display", "none");

  // Add this new row in the correct position.
  YAHOO.util.Dom.insertAfter(newRow, lastRow);
}

function delete_field(name, button) {
  var row = YAHOO.util.Dom.getAncestorByTagName(button, "div");
  var divs = YAHOO.util.Dom.getElementsByClassName("row-"+name, null, row.parentNode);

  var isLastRow = row == divs[divs.length-1];
  row.parentNode.removeChild(row);
  // Recreate the array to exclude the row.
  var divs = YAHOO.util.Dom.getElementsByClassName("row-"+name, null, row.parentNode);

  // If this was the last row, enable the add button for the previous row.
  if (isLastRow) {
    var newLastRow = divs[divs.length-1];
    var inputs = YAHOO.util.Dom.getElementsByClassName("hcp-button-add", null, newLastRow);
    YAHOO.util.Dom.setStyle(inputs[0], "display", "inline");
  }

  // If there is only one row left, disable the delete button.
  if (divs.length == 1) {
    var firstRow = divs[0];
    var inputs = YAHOO.util.Dom.getElementsByClassName("hcp-button-delete", null, firstRow);
    YAHOO.util.Dom.setStyle(inputs[0], "display", "none");
  }
}
